package com.zenith.edu.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zenith.edu.mapper.EduProgressMapper;
import com.zenith.edu.po.domain.EduProgress;
import com.zenith.edu.po.dto.EduProgressDTO;
import com.zenith.edu.po.vo.EduProgressVO;
import com.zenith.edu.service.EduProgressService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class EduProgressServiceImpl extends ServiceImpl<EduProgressMapper, EduProgress> implements EduProgressService {
    
    @Override
    public EduProgressVO createProgress(EduProgressDTO dto) {
        EduProgress progress = new EduProgress();
        BeanUtils.copyProperties(dto, progress);
        this.save(progress);
        
        EduProgressVO vo = new EduProgressVO();
        BeanUtils.copyProperties(progress, vo);
        return vo;
    }
    
    @Override
    public EduProgressVO getProgressById(Long id) {
        EduProgress progress = this.getById(id);
        if (progress == null) {
            return null;
        }
        
        EduProgressVO vo = new EduProgressVO();
        BeanUtils.copyProperties(progress, vo);
        return vo;
    }
    
    @Override
    public EduProgressVO updateProgress(EduProgressDTO dto) {
        EduProgress progress = new EduProgress();
        BeanUtils.copyProperties(dto, progress);
        this.updateById(progress);
        
        EduProgressVO vo = new EduProgressVO();
        BeanUtils.copyProperties(progress, vo);
        return vo;
    }
    
    @Override
    public boolean deleteProgress(Long id) {
        return this.removeById(id);
    }
    
    @Override
    public List<EduProgressVO> getProgressList() {
        List<EduProgress> progressList = this.list();
        return progressList.stream().map(progress -> {
            EduProgressVO vo = new EduProgressVO();
            BeanUtils.copyProperties(progress, vo);
            return vo;
        }).collect(Collectors.toList());
    }
}